package com.qianyu.project.utils;

import com.qianyu.project.core.context.user.FlowUserManager;
import com.qianyu.project.entity.SystemUser;
import com.qianyu.project.entity.TenderCompany;
import com.qianyu.project.service.ISystemUserService;
import com.qianyu.project.service.ITenderCompanyService;

/**
 * @author gs
 * @date create in 2021/2/3 12:56
 */
public class AssertTender {

    /**
     * description: 验证投标是否允许 <br/>
     * author: gs   <br/>
     * date: 2021/2/3 <br/>
     * params: [systemUserService, flowUserManager, tenderCompanyService, price] <br/>
     * return: void
     */
    public static Integer isValidate(ISystemUserService systemUserService, FlowUserManager flowUserManager, ITenderCompanyService tenderCompanyService,Double price) {
        //查询公司注册资本
        SystemUser systemUser = systemUserService.getById(flowUserManager.getFlowUser().getId());
        TenderCompany tenderCompany = tenderCompanyService.getById(systemUser.getCompanyId());
        //验证信息是否完善
        if(tenderCompany == null || tenderCompany.getRegisterCapital() == null){
            throw new RuntimeException("请先完善公司信息");
        }
        //验证是否可以投标
        double money = tenderCompany.getRegisterCapital().doubleValue() * 0.5;
        if (price > money) {
            throw new RuntimeException("竞标价格多余公司资金50%");
        }
        return systemUser.getCompanyId();
    }
}
